<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" :highlight="item.cars.status!='apply'" @click="goRecharge(item)">
				<view class="itme">
					<view class="line">
						<fui-text :text="item.parking.title" color="#000000" :size="32" style="margin-right: 10rpx;"></fui-text>
					</view>
					<view class="line">
						<fui-text :text="`车场服务电话：${item.parking.phone}`" color="#afafaf" :size="24" style="margin-right: 10rpx;"></fui-text>
					</view>
					<view class="line" v-if="rules_type=='monthly' || rules_type=='day'">
						<fui-text :text="'有效期至'+formatDate(item.cars.endtime)" color="#000000" :size="28" style="margin-right: 10rpx;"></fui-text>
						<fui-tag v-if="item.cars.status=='normal'" text="正常" type="success"></fui-tag>
						<fui-tag v-if="item.cars.status=='hidden'" text="禁用" type="danger"></fui-tag>
						<fui-tag v-if="item.cars.status=='expire'" text="已过期" type="danger"></fui-tag>
						<fui-tag v-if="item.cars.status=='apply'" :text="`续${isMonthly?'费':'期'}申请中`" type="warning"></fui-tag>
					</view>
					<view class="line" v-if="rules_type=='stored'">
						<fui-text :text="'余额：￥'+parseNumber(item.cars.balance)" color="#e6b31a" :size="28" style="margin-right: 10rpx;"></fui-text>
						<fui-tag v-if="item.cars.status=='normal'" text="正常" type="success"></fui-tag>
						<fui-tag v-if="item.cars.status=='hidden'" text="禁用" type="danger"></fui-tag>
						<fui-tag v-if="item.cars.status=='expire'" text="已过期" type="danger"></fui-tag>
					</view>
					<view class="line">
						<fui-text text="车牌号：" color="#afafaf" :size="24" style="margin-right: 10rpx;"></fui-text>
						<platetype :plate_number="item.plate_number" :plate_type="item.plate_type"></platetype>
					</view>
				</view>
				<fui-tag v-if="item.cars.status!='apply' && isMonthly" text="去续期" :padding="['12rpx','24rpx']" style="position: relative;top: 40rpx;"></fui-tag>
				<fui-tag v-if="item.cars.status!='apply' && isStored" text="去续费"  :padding="['12rpx','24rpx']" style="position: relative;top: 40rpx;"></fui-tag>
				<fui-tag v-if="item.cars.status!='apply' && isDay" text="查看详细" :padding="['12rpx','24rpx']" style="position: relative;top: 40rpx;"></fui-tag>
			</fui-list-cell>
			<fui-list-cell v-for="(item,index) in apply" :key="index" :highlight="false">
				<view class="itme">
					<view class="line">
						<fui-text :text="item.parking.title" color="#000000" :size="32" style="margin-right: 10rpx;"></fui-text>
					</view>
					<view class="line">
						<fui-text :text="`车场服务电话：${item.parking.phone}`" color="#afafaf" :size="24" style="margin-right: 10rpx;"></fui-text>
					</view>
					<view class="line">
						<fui-tag :text="`${rules_title[rules_type]}申请中`" type="warning"></fui-tag>
					</view>
					<view class="line">
						<fui-text text="车牌号：" color="#afafaf" :size="24" style="margin-right: 10rpx;"></fui-text>
						<platetype :plate_number="item.plate_number"></platetype>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0 && apply.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import platetype from '@/components/common/platetype.vue';
	import {formatDate,parseNumber} from '@/utils/util.js'
	export default {
		components:{
			platetype:platetype
		},
		data() {
			return {
				baseUrl:baseUrl,
				rules_type:'',
				rules_type_txt:{
					monthly:'我的月卡',
					day:'我的日卡',
					stored:'我的储值卡'
				},
				rules_title:{
					monthly:'月卡',
					day:'日卡',
					stored:'储值卡'
				},
				list:[],
				apply:[],
				isMonthly:false,
				isDay:false,
				isStored:false
			}
		},
		onLoad(e) {
			this.rules_type=e.rules_type || 'monthly';
			uni.setNavigationBarTitle({
				title:this.rules_type_txt[e.rules_type]
			});
			this.getList();
			if(this.rules_type=='monthly'){
				this.isMonthly=true;
			}
			if(this.rules_type=='day'){
				this.isDay=true;
			}
			if(this.rules_type=='stored'){
				this.isStored=true;
			}
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			parseNumber,
			goRecharge:function(item){
				if(item.cars && item.cars.status=='apply'){
					return;
				}
				this.$navigateTo(`index/${this.rules_type}?parking_id=${item.parking.id}&plate_number=${item.plate_number}`)
			},
			formatDate:function(time){
				return formatDate(new Date(time*1000));
			},
			getList:function(callback=false){
				this.$get('rules/list',{
					rules_type:this.rules_type
				},true).then(res=>{
					this.list=res.list;
					this.apply=res.apply;
					if(callback){
						callback();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.fui-wrap{
	padding: 24rpx;
}
.itme{
	height: 200rpx;
	display: flex;
	flex-direction: column;
	justify-content: space-around;
}
.line{
	display: flex;
	align-items: center;
	margin-bottom: 10rpx;
}
</style>